Use this notebook to visualise results generated from scripts/run_eval.py. Set the following variables:
%cd ..
c:\Users\s2558406\Documents\Repos\cmr-experiments
c:\Users\s2558406\Documents\Repos\cmr-experiments\venv\Lib\site-packages\IPython\core\magics\osm.py:417: UserWarning: This is now an optional IPython functionality, setting dhist requires you to install the `pickleshare` library.
self.shell.db['dhist'] = compress_dhist(dhist)[-100:]
from pathlib import PathRESULTS_FILE = Path('M:/models/cmr-experiments/CMRxRecon/DynamicMRI/eval_test_table_1_seed_1')RESULTS_FILE = Path('results/eval_test_table_1_seed_1')
import jsonfrom py_markdown_table.markdown_table import markdown_tablefrom itertools import zip_longestdef isnotNone(x): return x isnotNoneand x !=""def filt(lbl): return [results[id].get(lbl, "") foridin results.keys()]withopen(RESULTS_FILE.with_suffix(".json"), "r") as f: results = json.load(f)
titles, metrics, metrics_init = filt('title'), filt('metrics'), filt('metrics_init')titles = ["No learning"] + titlesmetrics = [metrics_init[-1]] + metrics #0 here arbitrary as all the same
data = [{"Method": title,"PSNR(norm)": round(metric[0], 2),"RescaleMinMaxPSNR": round(metric[1], 2),"MaxPixelPSNR": round(metric[2], 2),"MSE": round(metric[3], 5),"NMSE": round(metric[4], 5),"SSIM": round(metric[5], 4),"RescaleMinMaxSSIM": round(metric[6], 4),"MaxPixelSSIM": round(metric[7], 4),} for title, metric in zip_longest(titles, metrics)]print(markdown_table(data).set_params(row_sep="markdown").get_markdown())
import numpy as npimport torchimport deepinv as dinvdata = np.load((Path("results") / RESULTS_FILE.name).with_suffix(".npz"))if"table_1"in RESULTS_FILE.name: data_2 = np.load((Path("results") / (RESULTS_FILE.name +"_supp")).with_suffix(".npz"))def get_data(k):if k =="mask": vis = data["y"] !=0else:try: vis = data[k]exceptKeyError: vis = data_2[k] k = k.replace("t-ssdu-mc_esi", "t-ssdu*") vis = torch.tensor(vis) vis = torch.clamp(vis, -10, 10) vis = vis[..., 128:512-128, :] #crop to square of interestreturn k, visdef _plot_videos(*labels): titles, xs =list(zip(*[get_data(k) for k in labels]))return dinv.utils.plot_videos(xs, titles=titles, display=True, figsize=(2*len(labels), 2*len(xs[0])))